#ifndef BLOCK_H
#define BLOCK_H

#include "types.h"

class Block
{
private:
    static constexpr int blocks[][4][4] =
    {
        {
            {0,0,0,0},
            {0,1,1,0},
            {0,1,1,0},
            {0,0,0,0}
        },
        {
            {0,1,0,0},
            {0,1,0,0},
            {0,1,1,0},
            {0,0,0,0}
        },
        {
            {0,0,1,0},
            {0,0,1,0},
            {0,1,1,0},
            {0,0,0,0}
        },
        {
            {0,1,0,0},
            {0,1,1,0},
            {0,0,1,0},
            {0,0,0,0}
        },
        {
            {0,0,1,0},
            {0,1,1,0},
            {0,1,0,0},
            {0,0,0,0}
        },
        {
            {0,0,0,0},
            {0,0,1,0},
            {0,1,1,1},
            {0,0,0,0}
        },
        {
            {0,0,1,0},
            {0,0,1,0},
            {0,0,1,0},
            {0,0,1,0}
        }
    };  // 七种块的定义
    static bool initialized;
public:
    static Block* newRandomBlock(int (&area)[AREA_ROW][AREA_COL]);

private:
    int (&gameArea)[AREA_ROW][AREA_COL];
    Block(int idx, int (&area)[AREA_ROW][AREA_COL]);

public:
    int block[4][4];
    Border border;
    Position position;

    void findBorder();
    void rotate();
    bool canMove(Motion motion);
    void putDown();

    // 下属方法返回值统一为，发生了动作则true
    bool moveRotate();
    bool moveDown();
    bool moveLeft();
    bool moveRight();
};

#endif // BLOCK_H
